package com.sun.springbootfiledownload.exception;

import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

/**
 * @version 1.0
 * @Package: com.sun.springbootfiledownload.exception
 * @ClassName: FileUploadExceptionAdvice
 * @Author: sgq
 * @Date: 2025/4/9 9:53
 * @Description: TODD
 */
//@Order(1) // 确保自定义处理器优先级高于内置处理器
//@RestControllerAdvice
public class FileUploadExceptionAdvice extends ResponseEntityExceptionHandler {

    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public ResponseEntity<String> handleMaxSizeException(MaxUploadSizeExceededException exc) {
        return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body("上传文件过大!");
    }
}